
import SSF.OS.*;
import SSF.Net.*;
import com.renesys.raceway.SSF.*;
import com.renesys.raceway.DML.*;

public class RealtimeThrottle extends ProtocolSession {
    private long lastClock = -1;

    public void init() {
        new SimpleProcess(inGraph()) { 
	    public void action() {
	         if (lastClock>0) { 
		    long dt = 1000 + lastClock - System.currentTimeMillis();
		    if (dt>0)  try {Thread.sleep(dt);}catch(Exception any){}
		 }
		 lastClock = System.currentTimeMillis();
	         System.out.println("Tick "+inGraph().now()+" at "+
					new java.util.Date());
		 waitFor(Net.seconds(1.));
	    }
        };
    }
    public boolean push(ProtocolMessage msg, ProtocolSession from) {
	return false;
    }
}
